//****************************************************
// Porman Project 
// Filename: CRenderTarget.h
// Date: 2011/01/12
// Author: KengYu Lin
// Modify:
//****************************************************
#ifndef _CRENDERTARGET_H
#define _CRENDERTARGET_H
#include <string>
#include <map>
#include <vector>
#include "CRSDef.h"
#include "CRenderBase.h"
#include "CRenderViewport.h"

namespace Porman
{

namespace RS
{

class CRenderCamera;
class CRenderViewport;

class CRenderTargetData
{
public:
    CRenderTargetData( void ) : m_iWidth(800), m_iHeight(600) {}
    CRenderTargetData( const CRenderTargetData& l ) { (*this) = l; }
    CRenderTargetData& operator=( const CRenderTargetData& l )
    {
        m_iWidth = l.m_iWidth;
        m_iHeight = l.m_iHeight;
        return (*this);
    }

    int m_iWidth;
    int m_iHeight;
};

class CRenderTarget : public CRenderBase
{
public:
    CRenderTarget( const std::string& sName, unsigned int uiHash );
    virtual ~CRenderTarget( void );

    PRS_API void initial( int Width, int iHeight );
    PRS_API virtual void getMetrics( int& iWidth, int& iHeight );
    PRS_API virtual int getWidth( void ) { return m_hRTData.getData().m_iWidth; }
    PRS_API virtual int getHeight( void ) { return m_hRTData.getData().m_iHeight; }

    PRS_API bool addViewport( CRenderCamera* pCamera, int iZOrder = 0, float fOffsetX = 0.0f, float fOffsetY = 0.0f, float fWidth = 1.0f, float fHeight = 1.0f );
    PRS_API bool deleteRenderViewport( int iZOrder );
    PRS_API void deleteAllRenderViewports( void );
    PRS_API CRenderViewport* getViewport( int iZOrder );
    PRS_API int getNumViewports( void );

    virtual void swapBuffer( void ) {} //RenderWindow should override this function to switch buffer content.
    virtual void onSwap( void );
    virtual void onRender( void );

protected:
    CDataHandlerT<CRenderTargetData> m_hRTData;
    CRenderBaseManagerT<CRenderViewport> m_mapRenderViewports;
};

}//End RS

}//End namespace Porman

#endif